
define(function(require, exports, module) {
    "use strict";

    var result = {};
    // localStorage.setItem("_turl", "http://xjdev.zhugejinfu.com:9091/");
    // localStorage.setItem("_tdev", "28");
    var _url = localStorage.getItem("_turl") || "/";
    result.baseUrl = _url;

    // 缓存永久字段 localStorage
    result.word = (function() {
        var w = {
            // isLock: "_sasfdeassdf1", // 锁定交易
        };
        return {
            get: function(name) {
                if (typeof w[name] === "undefined") {
                    alert("请先存标志字段");
                    return null;
                }
                return localStorage.getItem(w[name]);
            },
            set: function(name, val) {
                if (!result.isLocalStorageSupported) return;
                if (typeof w[name] === "undefined") {
                    alert("请先存标志字段");
                    return;
                }
                localStorage.setItem(w[name], val);
            },
            remove: function(name) {
                if (typeof w[name] === "undefined") {
                    alert("请先存标志字段");
                    return;
                }
                localStorage.removeItem(w[name]);
            },
            boradCast: function(name, fn) {
                // window.removeEventListener("storage");
                window.addEventListener("storage",function(e){
                    // console.log("yess----" + e);
                    // e.key newValue: "22"oldValue: "1"
                    if (e.key === w[name]) {
                        fn && fn(e);
                    }
                },false);
            }
        }
    }());

    result.session = (function() {
        var w = {
            menuTog: "_aabldf1",  // 菜单是否隐藏
        };
        return {
            get: function(name) {
                if (typeof w[name] === "undefined") {
                    alert("请先存标志字段");
                    return null;
                }
                return sessionStorage.getItem(w[name]);
            },
            set: function(name, val) {
                if (typeof w[name] === "undefined") {
                    alert("请先存标志字段");
                    return;
                }
                sessionStorage.setItem(w[name], val);
            },
            remove: function(name) {
                if (typeof w[name] === "undefined") {
                    alert("请先存标志字段");
                    return;
                }
                sessionStorage.removeItem(w[name]);
            }
        }
    })();

    // 是否支持缓存
    result.isLocalStorageSupported = (function() {
        var testKey = 'test',
            storage = window.localStorage;
        try {
            storage.setItem(testKey, 'testValue');
            storage.removeItem(testKey);
            return true;
        } catch (error) {
            return false;
        }
    })();

    module.exports = result;
});
